package com.ag.zrt.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;

import com.ag.bean.TbInformation;
import com.ag.common.IDUtil;

public class TbInformationDAO extends com.ag.dao.TbInformationDAO {
	private static final Log log = LogFactory.getLog(TbInformationDAO.class);

	public List find(String hql, Object value) {
		log.debug("finding TbInformation instance with property: " + hql
				+ ", value: " + value);
		try {
			return getHibernateTemplate().find(hql, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List find(String hql, int nextBeginRecordsNum) {
		log.debug("finding TbInformation instance with property: " + hql
				+ ", nextBeginRecordsNum: " + nextBeginRecordsNum);
		try {
			Session session = this.getSessionFactory().openSession();
			session.beginTransaction();
			Query query = (Query) session.createQuery(hql).setFirstResult(
					nextBeginRecordsNum).setMaxResults(IDUtil.INFORITEMS);
			List<TbInformation> list = query.list();
			session.getTransaction().commit();
			session.close();
			//List<TbInformation> list = getHibernateTemplate().find(hql);
			return list;
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List find(String hql) {
		log.debug("finding all TbInformation instances");
		try {
			return getHibernateTemplate().find(hql);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public int countAll(String hql) {
		log.debug("count all records num");
		try {
			return ((Long) getHibernateTemplate().find(hql).get(0)).intValue();
		} catch (RuntimeException re) {
			log.error("count num failed", re);
			throw re;
		}
	}

	public TbInformation findById(java.lang.String id, String hql) {
		log.debug("getting TbInformation instance with id: " + id);
		try {
			return (TbInformation) getHibernateTemplate().find(hql, id).get(0);
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

}
